package com.baizhi.service;

import com.baizhi.dao.AdminDao;
import com.baizhi.entity.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminDao adminDao;


    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public Map<String, String> login(Admin admin) {
        HashMap<String,String> map=new HashMap<>();
        Admin admin1 = adminDao.queryOne(admin.getUsername());
        if(admin1!=null){
            if(admin1.getPassword().equals(admin.getPassword())){
                map.put("status","成功");
                map.put("username",admin1.getUsername());
            }else{
                map.put("status","密码错误");
            }
        }else{
            map.put("status","用户名不存在");
        }

        return map;
    }
}
